package com.sskj.mine.util;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.bulong.rudeness.RudenessScreenHelper;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.lib.adapter.BaseAdapter;
import com.sskj.lib.adapter.ViewHolder;
import com.sskj.mine.R;
import com.sskj.common.base.App;
import com.sskj.common.util.ClickUtil;
import com.sskj.mine.bean.LockHouseBean;
import com.sskj.mine.ui.fragment.MineFragment;

import java.util.ArrayList;
import java.util.List;

public class TipMineUtil {
    public static MaterialDialog getTip(Context context, String content, OnTipSure onTipSure) {
        return getTip(context, content, App.INSTANCE.getString(R.string.mineTipUtil0), onTipSure);
    }

    public static MaterialDialog getTip(Context context, String content, String sureMsg, OnTipSure onTipSure) {
        return new MaterialDialog.Builder(context)
                .title(App.INSTANCE.getString(R.string.mineTipUtil1))
                .content(content)
                .positiveText(sureMsg)
                .negativeText(App.INSTANCE.getString(R.string.mineTipUtil2))
                .onAny((dialog, which) -> {
                    if (which == DialogAction.POSITIVE) {
                        dialog.dismiss();
                        onTipSure.onSure();
                    } else if (which == DialogAction.NEGATIVE) {
                        dialog.dismiss();
                    }
                }).build();
    }

    public static MaterialDialog getTip(Context context, String title, String content, String sureMsg, OnTipSure onTipSure) {
        return new MaterialDialog.Builder(context)
                .title(title)
                .content(content)
                .positiveText(sureMsg)
                .negativeText(App.INSTANCE.getString(R.string.mineTipUtil2))
                .onAny((dialog, which) -> {
                    if (which == DialogAction.POSITIVE) {
                        dialog.dismiss();
                        onTipSure.onSure();
                    } else if (which == DialogAction.NEGATIVE) {
                        dialog.dismiss();
                    }
                }).build();
    }

    public static void getShowAboutUS(Context context, String title, String content, String copy
            , OnTipSure onTipSure) {

        MaterialDialog dialog = new MaterialDialog.Builder(context)
                .customView(R.layout.mine_dialog_tip, false)
                .autoDismiss(false)
                .cancelable(false)
                .show();
        View customeView = dialog.getCustomView();

        ((TextView) customeView.findViewById(R.id.tvTitle)).setText(title);
        ((TextView) customeView.findViewById(R.id.tvContent)).setText(content);
        ((TextView) customeView.findViewById(R.id.tvSure)).setText(copy);
        ClickUtil.click(customeView.findViewById(R.id.tvCancel), () -> {
            dialog.dismiss();
        });
        ClickUtil.click(customeView.findViewById(R.id.tvSure), () -> {
            dialog.dismiss();
            onTipSure.onSure();
        });
    }

    public static void getLockDataList(Context context, List<LockHouseBean.ListBean> lockTypes, OnTipLockSure onTipSure) {

        MaterialDialog dialog = new MaterialDialog.Builder(context)
                .customView(R.layout.mine_lock_tip, false)
                .autoDismiss(false)
                .cancelable(true)
                .show();
        View customeView = dialog.getCustomView();
        RecyclerView recyclerLock = customeView.findViewById(R.id.recy_lock_data);

        recyclerLock.setLayoutManager(new LinearLayoutManager(context));
        recyclerLock.addItemDecoration(new DividerLineItemDecoration(context)
                .setFirstDraw(false)
                .setLastDraw(false)
                .setDividerColor(ContextCompat.getColor(App.INSTANCE, R.color.mine_525869))
                .setPaintWidth((int) RudenessScreenHelper.pt2px(App.INSTANCE, 2)));
        BaseAdapter<LockHouseBean.ListBean> mineAdapter = new BaseAdapter<LockHouseBean.ListBean>(R.layout.mine_item_lock_tip, new ArrayList<>(), recyclerLock) {
            @Override
            public void bind(ViewHolder holder, LockHouseBean.ListBean item) {
                holder.setText(R.id.tv_item_lock, item.getLockday())
                        .getConvertView().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        onTipSure.onSure(item);
                        dialog.dismiss();
                    }
                });
            }
        };
        mineAdapter.addData(lockTypes);
    }

    public interface OnTipSure {
        void onSure();
    }

    public interface OnTipLockSure {
        void onSure(LockHouseBean.ListBean data);
    }
}
